package com.mark.basic.service.Impl;

import com.mark.basic.mapper.BaseMapper;
import com.mark.basic.query.BaseQuery;
import com.mark.basic.service.IBaseService;
import com.mark.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    BaseMapper<T> basicMapper;
    @Override
    public List<T> listAll() {
        return basicMapper.listAll();
    }

    @Override
    public T listById(Long id) {
        return basicMapper.listById(id);
    }

    @Override
    public void add(T t) {
        basicMapper.add(t);
    }

    @Override
    public void update(T t) {
        basicMapper.update(t);
    }

    @Override
    public void del(Long id) {
        basicMapper.del(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery basicquery) {
        Long total = basicMapper.queryCount(basicquery);
        if (total < 1){
            return new PageList<>();
        }
        List<T> rows = basicMapper.queryData(basicquery);
        return new PageList<>(total,rows);
    }

    @Override
    public void batchRemove(List<Long> ids) {
        basicMapper.batchRemove(ids);
    }
}
